package com.crm.dao.client;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.crm.pojo.ClientInfo;
import com.crm.pojo.Contact;
import com.crm.vo.ContactIdAndNameVo;

public interface ContactDao extends CrudRepository<Contact, Long>,JpaSpecificationExecutor<Contact> {

	@Query("from Contact c where c.isDel != '是' order by c.contactid desc")
	public List<Contact> findAllContactsNoDel(Pageable pageable);

	@Query("select count(*) from Contact c where c.isDel != '是' ")
	public Long countContactsNoDel();

	@Query("from Contact c where c.isDel != '是' and c.contactName like ?1 order by c.contactid desc")
	public List<Contact> findContactByNameNotDel(String contactName);
	
	@Query("select new com.crm.vo.ContactIdAndNameVo(c.contactid, c.contactName) from Contact c where c.isDel != '是' order by c.contactid desc")
	public List<ContactIdAndNameVo> findContactIdAndName();
	
	@Query("select new com.crm.vo.ContactIdAndNameVo(c.contactid, c.contactName) from Contact c where c.isDel != '是' and c.clientInfo.cid = ?1")
	public List<ContactIdAndNameVo> findContactIdAndNameByCid(Long cid);

	//查询联系人根据采购商cid
	@Query("from Contact c where c.clientInfo.cid=?1  and c.isDel != '是'")
	public List<Contact> findAllBycnameAndcidBymh(Long cid);
	
}
